package com.hzhanghuan.materialsearchview;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


/**
 * Created by Administrator on 2016/7/12.
 */
public class SuggestionAdapter extends BaseAdapter {


    private List<Suggestion> mSuggestions = new ArrayList<>();


    public SuggestionViewListener mSuggestionViewListener;





    public void setSuggestionViewListener(SuggestionViewListener mSuggestionViewListener) {
        this.mSuggestionViewListener = mSuggestionViewListener;
        notifyDataSetChanged();
    }





    public SuggestionAdapter(Collection<Suggestion> mSuggestions) {
        this.mSuggestions = new ArrayList<>(mSuggestions);
    }





    public void setSuggestions(Collection<Suggestion> mSuggestions) {
        this.mSuggestions = new ArrayList<>(mSuggestions);
        notifyDataSetChanged();
    }





    @Override
    public int getCount() {
        return mSuggestions == null ? 0 : mSuggestions.size();
    }





    @Override
    public Object getItem(int position) {
        return mSuggestions.get(position);
    }





    @Override
    public long getItemId(int position) {
        return position;
    }





    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Suggestion suggestion = mSuggestions.get(position);
        return mSuggestionViewListener.getView(position, suggestion, convertView, parent);
    }
}
